/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

import java.io.Serializable;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 *
 * @author damianfernandez
 */
@SessionScoped
public class FacesMessageHelper implements Serializable{
    
    public String getMessage(String fileName, String messageName){
        FacesContext context=FacesContext.getCurrentInstance();
        Locale locale=context.getViewRoot().getLocale();
        ResourceBundle rb = ResourceBundle.getBundle(fileName, locale);
        String successMessage=rb.getString(messageName);
        return successMessage;
    }
    
    public void printMessage(String fileName, String messageName, FacesMessage.Severity severity){
        FacesContext context=FacesContext.getCurrentInstance();
        Locale locale=context.getViewRoot().getLocale();
        ResourceBundle rb = ResourceBundle.getBundle(fileName, locale);
        String message=rb.getString(messageName);
        FacesMessage facesMessage = new FacesMessage(severity, message, message);  
        context.addMessage(null, facesMessage); 
        context.renderResponse();
    }
}
